﻿@using EC.Entity.Enum
@{
    Layout = "~/Views/Shared/_Dialog.cshtml";
}
@model EC.Entity.Response.Token.TokenResponse
<section class="container-fluid" style="background-color: white;">
    <form class="form-horizontal m15_t" id="form">
        <div class="tab-content">
            <input type="hidden" id="merchantId" name="merchantId" value="@(Model.MerchantId)">
            <div class="tab-pane fade in active" id="home">
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>AppId：</label>
                    <div class="wd350 m15_l">
                        <input class="form-control" type="text" name="appId" maxlength="32" value="@(Model.AppId)" autocomplete="off" placeholder="AppId由11位数字组成">
                    </div>
                    <input class="m5_l btn-success wd95 btnAddApiKey" type="button" value="生成AppKey" id="btnAddAppKey" />
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>AppSecret：</label>
                    <div class="wd450 m15_l">
                        <input class="form-control" type="text" name="appSecret" maxlength="64" value="@(Model.AppSecret)" autocomplete="off" placeholder="AppSecret由32位字母或数字组成">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>状态：</label>
                    <div class="wd275 m15_l">
                        <label class="m10_r">
                            <input type="radio" name="status" value="@((int)TokenStatus.启用)" @(Model.Status.Equals((int)TokenStatus.启用) ? "checked" : "")> 启用
                        </label>
                        <label>
                            <input type="radio" name="status" value="@((int)TokenStatus.禁用)" @(Model.Status.Equals((int)TokenStatus.禁用) ? "checked" : "")> 禁用
                        </label>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
@section footerScript{
    <script type="text/javascript">

        //生成ApiKey
        $("#btnAddAppKey").click(function () {

            let typeKey = $("input[name='appId']").val();

            FlashPay.UI.Confirm({
                content: "确定要生成新的AppKey吗？",
                ok: function () {
                    FlashPay.Util.Ajax({
                        type: "POST",
                        url: "/Merchant/GetNewKeyByDeposit",
                        data: {},
                        success: function (data) {
                            if (data.success) {
                                FlashPay.Util.SetInputVal("appId", data.statusCode);
                                FlashPay.Util.SetInputVal("appSecret", data.message);
                            } else {
                                FlashPay.UI.Tip_warning("生成AppKey失败！");
                                return;
                            }
                        },
                        error: function (e) {
                            FlashPay.UI.Tip_warning("生成AppKey错误！");
                        }
                    });
                }
            });
        });



        function save() {

            //let appId = $("input[name='appId']").val();
            //let secretKey = $("input[name='appSecret']").val();
            //if (FlashPay.Util.isNullOrEmptySpance(appId) || FlashPay.Util.isNullOrEmptySpance(secretKey)) {
            //    FlashPay.UI.Tip_warning("请点击生成存款ApiKey和SecretKey！");
            //    return;
            //}

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            var data = $("#form").serializeJSON();
            //状态
            //data.status = $("input[name='status'][checked]").val();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Merchant/SaveToken",
                data: data,
                success: function (res) {
                    if (res.success) {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        cover.Remove();
                        FlashPay.UI.Tip_short_warning("操作失败！" + res.message);
                    }
                },
                error: function (json) {
                    cover.Remove();
                    FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                }
            });

        }
    </script>
}